import { Component, OnInit } from '@angular/core';
import {FormArray, FormControl, FormGroup} from "@angular/forms";

@Component({
  selector: 'app-reactive-form',
  templateUrl: './reactive-form.component.html',
  styleUrls: ['./reactive-form.component.css']
})
export class ReactiveFormComponent implements OnInit {

  username:FormControl = new FormControl("aaa");// 表单默认值


  formModel:FormGroup = new FormGroup({
    usernames: new FormControl("aaa"),// 表单默认值
    dateRange: new FormGroup({
      from: new FormControl(),
      to: new FormControl()
    }),
    emails: new FormArray([
      new FormControl("a@a.com"),
      new FormControl("b@b.com"),
    ])
  });// 起始日期-结束日期

  // from: new FormControl(),
  // to: new FormControl()



  constructor() { }

  ngOnInit() {
  }

  onsubmit() {
    console.log(this.formModel.value);
  }

  addEmail() {
    let emails = this.formModel.get("emails") as FormArray;
    emails.push(new FormControl());
  }

}
